package com.tieto;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.QueryHint;
import javax.persistence.Transient;

@Entity
@NamedQueries({
		@NamedQuery(name = "selectAllPersons", query = "select person from Person person"),
		@NamedQuery(name = "selectSinglePerson", query = "select person from Person person where person.id = ?1", hints = { @QueryHint(name = "openjpa.FetchPlan.ReadLockMode", value = "WRITE") }) })
public class Person {
	@Id
	@GeneratedValue
	protected int id;
	protected String firstName;
	protected char middleInitial;
	protected String lastName;
	protected String streetAddress1;
	protected String streetAddress2;
	protected String city;
	protected String state;
	protected String zip;
	protected Date time;
	@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
	@JoinTable(name = "PERSON_PLAYERS", joinColumns = @JoinColumn(name = "player_id", referencedColumnName = "ID"))
	protected List<Player> players;
	@Transient
	protected List<String> strings;

	public Person() {

	}

	public Person(final String fn, final char mi, final String ln,
			final String sa1, final String sa2, final String city,
			final String state, final String zip, Date time) {
		setFirstName(fn);
		setMiddleInitial(mi);
		setLastName(ln);
		setStreetAddress1(sa1);
		setStreetAddress2(sa2);
		setCity(city);
		setState(state);
		setZip(zip);
		setTime(time);
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public char getMiddleInitial() {
		return middleInitial;
	}

	public void setMiddleInitial(char middleInitial) {
		this.middleInitial = middleInitial;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getStreetAddress1() {
		return streetAddress1;
	}

	public void setStreetAddress1(String streetAddress1) {
		this.streetAddress1 = streetAddress1;
	}

	public String getStreetAddress2() {
		return streetAddress2;
	}

	public void setStreetAddress2(String streetAddress2) {
		this.streetAddress2 = streetAddress2;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		this.zip = zip;
	}

	public List<Player> getPlayers() {
		return players;
	}

	public void setPlayers(List<Player> players) {
		this.players = players;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public List<String> getStrings() {
		return strings;
	}

	public void setStrings(List<String> strings) {
		this.strings = strings;
	}
}